#ifndef __CHILDVEINFINDER__H
#define __CHILDVEINFINDER__H
#include <vector>
#include "Image.h"
#include "View.h"
#include "JunctionFinder.h"
#include "VeinWalker.h"
class ChildVeinFinder : protected ViewBW
{
public:
	/** some information regarding the vein we found */
	struct Info {
		Info() : m_stateFirst(0, 0, 0) {}
		/** the point on which we created the VeinWalker which gave us the vein */
		ViewState m_stateFirst;
		/** the info we got from GetVeinInfo */
		VeinWalker::Info m_infoVein;
	};
	
	ChildVeinFinder(Image *pImage) : ViewBW(pImage, 0, 0, 0) { m_nRunIndex = -2; }
	void Init(bool bOpposite, const VeinWalker::Criteria *pCritWalker, 
	          const std::vector < ViewState > *pVecState1,
	          const std::vector < ViewState > *pVecState2, const JunctionFinder::Info *pJi);
	bool Next(Info *pInfo);
	bool Invalid() const;
private:
	void SetStateForNext();
	void SetStateForNextInOtherView(View *pView, S32 nState);
	/** @return index of the run that is closest to main vein or -1 if there is no such
	 *          (for example in the case where the main vein splits into two and then ends)
	 */
	S32 GetRunClosestToMainVein();
	/** fakes a connection of ViewStates from another ViewState to our ViewState
	 *  @param pInfo - pointer to vector to which we output the fake the data
	 *  @param pDestState - pointer to the other ViewState
	 */
	void FakeConnection(const ViewState *pSrcState, std::vector < ViewState > *pVec) const;
	const std::vector < ViewState > *m_pVecState1;
	const std::vector < ViewState > *m_pVecState2;
	const JunctionFinder::Info *m_pJunctionInfo;
	bool m_bOpposite;
	bool m_bAt90;
	S32 m_nNodeIndex;
	S32 m_nRunIndex; // in a node, which run is checked. special values: -2, pre-init, -1 first time
	bool m_bLastRunWasBlockedBelow;
	Run m_run;
	std::vector<Run> m_vecRuns;
	S32 m_nMainVeinRun;
	/** criteria arguments to be given to VeinWalker */
	VeinWalker::Criteria m_critWalker;
};
#endif//__CHILDVEINFINDER__H
